import userTempldId from "@/utils/userTempId";
import { getItem, setItem, removeItem } from "@/utils/localStorage";

import { reqLogin, requserMessage } from "@/api";


const state = {
  userTempId: userTempldId(),
  toKen: getItem("token") || "",
  userMessage: {}
};
const mutations = {
  set_token(state, payload) {
    state.toKen = payload.token;
    setItem("token", payload.token);
  },
  set_userMessage(state, payload) {
    state.userMessage = payload.Message;
  },
  remove_token(state) {
    state.toKen = "";
    removeItem("token");
    state.userMessage = {};
  }
};
const actions = {
  async getToken(store, userInfo) {
    const result = await reqLogin(userInfo);
    store.commit('set_token', { token: result.token });
  },

  async getuserMessage({ commit }) {
    const result = await requserMessage();
    commit("set_userMessage", { Message: result });
  }
};
const getters = {};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
};